/**
 *	all functions related to the 'LoginPage' view
**/

if (typeof Controllers === "undefined") {
	var Controllers = { }
}

Controllers.LoginPage = {
	
	//'start' button - do some error checking then store the results
	begin: function() {
		var el = {
			user: document.getElementById('LPuser'),
			game: document.getElementById('LPgamelist'),
		}
		
		// alphanumeric, no spaces
		var regexp = /^[A-Za-z1-9_]{1,20}$/
		
		//error checking
		if (el.user.value == '') {
			alert('please enter a username')
			return
		} else if ( regexp.test(el.user.value) === false ) {
			alert('user name is invalid. alphanumeric characters and underscore only please!')
			return
		}
		
		//store this info somewhere useful
		Main.clientInfo = {
			online: true,
			user: el.user.value,
			gameType: el.game.options[el.game.selectedIndex].value
		}
		
		Main.goTo('MatchPage')
	}
	
}